package vn.edu.hcmut.cse.ai.search.problems.npuzzle;

import vn.edu.hcmut.cse.ai.infrastructure.Action;
import vn.edu.hcmut.cse.ai.infrastructure.ActionCost;
import vn.edu.hcmut.cse.ai.infrastructure.Node;
import vn.edu.hcmut.cse.ai.infrastructure.Problem;

/**
 *
 * @author minhl_000
 */
public class NPuzzleProblem extends Problem {

    public NPuzzleProblem(NPuzzleState initialState, NPuzzleActions actions, NPuzzleGoalTest goalTest, ActionCost actionCost) {
        super(initialState, actions, goalTest, actionCost);
    }

    @Override
    public Node getChildNode(Node node, Action action) {
        NPuzzleAction nPuzzleAction = (NPuzzleAction) action;

        NPuzzleState nPuzzleState = new NPuzzleState((NPuzzleState) node.getState());
        switch (nPuzzleAction.getActionType()) {
            case LEFT:
                nPuzzleState.moveLeft();
                break;
            case RIGHT:
                nPuzzleState.moveRight();
                break;
            case UP:
                nPuzzleState.moveUp();
                break;
            case DOWN:
                nPuzzleState.moveDown();
                break;
            default:
                return null;
        }

        double stepCost = this.actionCost.actionCost(node.getState(), nPuzzleState, action);
        Node returnNode = new Node(nPuzzleState, node, nPuzzleAction, stepCost);
        return returnNode;
    }

}
